import sys
sys.path.append("../")

from selenium import webdriver
from frameworks.cores.Config import *

class BaseController:
    def __init__(self):
        self.driver = self.create_driver()
        self.config = Config()
        self.apiConfig = self.config.getApi()

    def create_driver(self):
        options = webdriver.ChromeOptions()
        options.add_experimental_option("debuggerAddress", "127.0.0.1:9527")
        driver = webdriver.Chrome(executable_path=r'D:\chromedriver-win64\chromedriver.exe', options=options)
        return driver

    def orderWindows(self):
        # 遍历窗口，确定窗口顺序
        self.windows = self.driver.window_handles
        self.windownames = {}
        for i in range(0, len(self.windows)):
            self.driver.switch_to.window(self.windows[i])
            self.windownames[self.driver.title] = i

    def quit_driver(self):
        if self.driver:
            self.driver.quit()